package com.zhoug.zmui.list;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhoug.common.adapters.recycler2.BaseRecyclerViewAdapter;
import com.zhoug.common.adapters.recycler2.BaseViewHolder;
import com.zhoug.zmui.R;

import java.util.List;

import androidx.annotation.Nullable;

/**
 * 实现的选择列表数据适配器
 * @Author: zhoug
 * @Date: 2024-07-05
 * @Description:
 */
public abstract class SimpleSelectListAdapter<T> extends BaseRecyclerViewAdapter<T> implements SelectListAdapter<T> {
    private final ListSelectHelper<T> mHelper;

    public abstract String getItemName(T itemData);

    public SimpleSelectListAdapter() {
        mHelper=new ListSelectHelper<>(this);
    }

    public SimpleSelectListAdapter(Context context) {
        super(context);
        mHelper=new ListSelectHelper<>(this);
    }



    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.zmui_simple_single_select_list_item;
    }

    @Override
    protected void onBindData(BaseViewHolder holder, T data, int position, int viewType) {
        if (data != null) {
            TextView tv_selectName = holder.getView(R.id.tv_selectName);
            ImageView iv_selected = holder.getView(R.id.iv_selected);
            tv_selectName.setText(getItemName(data));
            mHelper.bindData(data,holder.itemView,tv_selectName, iv_selected);
        }
    }

    @Override
    public void notifyDataChange() {
        notifyDataChange(false);
    }

    @Override
    public void notifyDataChange(boolean callSelectChange) {
        notifyDataSetChanged1();
        if(callSelectChange){
            mHelper.onSelectChange();
        }
    }


    public void showSelectImage(boolean show) {
        mHelper.showSelectImage(show);
    }
    public void setTextAlign(int textAlign) {
        mHelper.setTextAlign(textAlign);
    }
    @Override
    public void setSelect(List<T> data) {
        mHelper.setSelect(data);

    }


    @Override
    public void clearSelect() {
        mHelper.clearSelect();
    }

    @Nullable
    @Override
    public List<T> getSelect() {
        return mHelper.getSelect();
    }
    @Nullable
    @Override
    public T getSingleSelect() {
        return mHelper.getSingleSelect();
    }
    @Override
    public void setSelect(T data) {
        mHelper.setSelect(data);
    }

    @Override
    public void addSelect(List<T> data) {
        mHelper.addSelect(data);
    }

    @Override
    public void addSelect(T data) {
        mHelper.addSelect(data);
    }

    @Override
    public void clearSelect(T data) {
        mHelper.clearSelect(data);
    }

    @Override
    public void setMultiSelect(boolean multi) {
        mHelper.setMultiSelect(multi);
    }

    @Override
    public boolean isSelect(T data) {
        return mHelper.isSelect(data);
    }

    @Override
    public boolean isMultiSelect() {
        return mHelper.isMultiSelect();
    }

    @Override
    public void setCancelSelectEnabled(boolean enabled) {
        mHelper.setCancelSelectEnabled(enabled);
    }

    @Override
    public void setEnabled(boolean enabled) {
        mHelper.setEnabled(enabled);
    }


    @Override
    public void setOnSelectChangeListener(OnSelectChangeListener<T> onSelectChangeListener) {
        mHelper.setOnSelectChangeListener(onSelectChangeListener);
    }



}
